<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Test_Database {

	public $CI;
    public $error;
    private $datebase;
    private $dbc;

    public function __construct()
    {
        $this->CI =& get_instance();
        $this->database = false;
        $this->dbc = false;
        $this->error = false;
    }

    public function test()
    {
        if ($this->CI->input->cookie('database'))
        {
            $this->database = $this->CI->input->cookie('database');
        }
        else if ($this->CI->input->post('database'))
        {
            $this->database = $this->CI->input->post('database');
        }

        if (!$this->database)
        {
            $this->dbc = $this->CI->load->database();
        }
        else
        {
            $this->dbc = $this->CI->load->database($this->database, TRUE);
        }

        if ('NULL' == $this->dbc)
        {
            exit('Invalid database connection');
        }

    }

    public function get_environment()
    {
        switch ($this->database) {
            case 'default':
                return '工作环境';
                break;
            case 'test':
                return '测试环境';
                break;
            default:
                exit('Invalid database connection.');
                break;
        }
    }

    public function get_db()
    {
        return $this->database;
    }

    public function get_dbc()
    {
        return $this->dbc;
    }

}

?>